package cn.com.forever.array;

import java.util.Scanner;

/*
    斐波那契数列
 */
public class Fibonacci {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(fibonacci2(n));
    }

    public static int fibonacci(int n){
        if(n < 0){
            return -1;
        }
        else if(n == 0){
            return 0;
        }
        else if(n == 1){
            return 1;
        }
        else{
            return fibonacci(n-1)+fibonacci(n-2);
        }
    }

    //不用递归
    public static int fibonacci2(int n){
        if(n < 0){
            return -1;
        }
        if(n == 0){
            return 0;
        }
        if(n == 1){
            return 1;
        }
        int zero = 0;
        int first = 1;
        int result = 0;
        for (int i = 2; i <= n; i++) {
            result = zero+first;
            zero = first;
            first = result;
        }
        return result;
    }
}
